package com.yuandm.wxnt.adapter;

import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.loopj.android.image.SmartImageView;
import com.yuandm.wxnt.MainActivity;
import com.yuandm.wxnt.R;
import com.yuandm.wxnt.bean.NewsData;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Administrator
 * @time 2016/1/4 11:20
 * @des ${TODO}
 * @updateAuthor $Author$
 * @updateDate $Date$
 * @updateDes ${TODO}
 */
public class NewsAdapter extends BaseAdapter{
    public List<NewsData.ListData.NewsList> m_newsData = new ArrayList<NewsData.ListData.NewsList>();
    public MainActivity m_mainActivity;

    @Override
    public int getCount() {
        return m_newsData.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {


            convertView = View.inflate(m_mainActivity, R.layout.newslist_item, null);
            ViewHolder holder = new ViewHolder();
            holder.tv_source = (TextView) convertView.findViewById(R.id.newslist_item_source);
            holder.iv_newsPic = (SmartImageView) convertView.findViewById(R.id.listview_item_pic);
            holder.tv_title = (TextView) convertView.findViewById(R.id.newslist_item_title);
            holder.tv_des = (TextView) convertView.findViewById(R.id.newslist_item_digest);
            holder.tv_time = (TextView) convertView.findViewById(R.id.newslist_item_ptime);



        //设置数据

        NewsData.ListData.NewsList newsData = m_newsData.get(position);
        //设置标题
        holder.tv_title.setText(newsData.title);
        holder.tv_des.setText(newsData.smalltext);

        //设置来源
        holder.tv_source.setText("今日南通");

        //设置时间
        holder.tv_time.setText(newsData.newspath);

        if(""==newsData.titlepic||newsData.titlepic.equals("null")){
            holder.iv_newsPic.setVisibility(View.GONE);
        }
        else {
            holder.iv_newsPic.setImageUrl(newsData.titlepic);
        }


        return convertView;
    }

    public class ViewHolder{
        SmartImageView iv_newsPic;
        TextView tv_title;
        TextView tv_des;
        TextView tv_time;
        TextView tv_source;
    }
}
